package model

import (
	"database/sql"
	"time"

	"github.com/guregu/null"
	"github.com/satori/go.uuid"
)

var (
	_ = time.Second
	_ = sql.LevelDefault
	_ = null.Bool{}
	_ = uuid.UUID{}
)

/*
DB Table Details
-------------------------------------


CREATE TABLE "customers"
(
    [CustomerId] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    [FirstName] NVARCHAR(40)  NOT NULL,
    [LastName] NVARCHAR(20)  NOT NULL,
    [Company] NVARCHAR(80),
    [Address] NVARCHAR(70),
    [City] NVARCHAR(40),
    [State] NVARCHAR(40),
    [Country] NVARCHAR(40),
    [PostalCode] NVARCHAR(10),
    [Phone] NVARCHAR(24),
    [Fax] NVARCHAR(24),
    [Email] NVARCHAR(60)  NOT NULL,
    [SupportRepId] INTEGER,
    FOREIGN KEY ([SupportRepId]) REFERENCES "employees" ([EmployeeId])
		ON DELETE NO ACTION ON UPDATE NO ACTION
)

JSON Sample
-------------------------------------
{    "customer_id": 36,    "first_name": "QoLalVGwOcIWEWvReglffDqQy",    "state": "gsFPrvNSDkSpgmVvvdByvwKbL",    "fax": "gjGKVoIVIkefXHZmwyqOyTLXA",    "email": "ZtsBinRNAUtPmBjODlwNHWsxS",    "phone": "MJWGkOSZWyrOePeCOGhZgRFwR",    "support_rep_id": 95,    "last_name": "YFpUevFuQXPHEJdBXWQMWVqBv",    "company": "jRkluGfDRcHsYWYjWRJcduSBu",    "address": "EWascyhpZeTXWleMkhgdvUgSk",    "city": "yuxZTaxImPKBhQumDqSIkkxxk",    "country": "BJcvPPqxgcyBYSwaOlPXRhLhG",    "postal_code": "fNYXZCKugWwJspdPJIGiohQfn"}



*/

// Customers struct is a row record of the customers table in the main database
type Customers struct {
	//[ 0] CustomerId                                     integer              null: false  primary: true   isArray: false  auto: true   col: integer         len: -1      default: []
	CustomerID int32 `gorm:"primary_key;AUTO_INCREMENT;column:CustomerId;type:integer;" json:"customer_id"`
	//[ 1] FirstName                                      nvarchar(40)         null: false  primary: false  isArray: false  auto: false  col: nvarchar        len: 40      default: []
	FirstName string `gorm:"column:FirstName;type:nvarchar;size:40;" json:"first_name"`
	//[ 2] LastName                                       nvarchar(20)         null: false  primary: false  isArray: false  auto: false  col: nvarchar        len: 20      default: []
	LastName string `gorm:"column:LastName;type:nvarchar;size:20;" json:"last_name"`
	//[ 3] Company                                        nvarchar(80)         null: true   primary: false  isArray: false  auto: false  col: nvarchar        len: 80      default: []
	Company sql.NullString `gorm:"column:Company;type:nvarchar;size:80;" json:"company"`
	//[ 4] Address                                        nvarchar(70)         null: true   primary: false  isArray: false  auto: false  col: nvarchar        len: 70      default: []
	Address sql.NullString `gorm:"column:Address;type:nvarchar;size:70;" json:"address"`
	//[ 5] City                                           nvarchar(40)         null: true   primary: false  isArray: false  auto: false  col: nvarchar        len: 40      default: []
	City sql.NullString `gorm:"column:City;type:nvarchar;size:40;" json:"city"`
	//[ 6] State                                          nvarchar(40)         null: true   primary: false  isArray: false  auto: false  col: nvarchar        len: 40      default: []
	State sql.NullString `gorm:"column:State;type:nvarchar;size:40;" json:"state"`
	//[ 7] Country                                        nvarchar(40)         null: true   primary: false  isArray: false  auto: false  col: nvarchar        len: 40      default: []
	Country sql.NullString `gorm:"column:Country;type:nvarchar;size:40;" json:"country"`
	//[ 8] PostalCode                                     nvarchar(10)         null: true   primary: false  isArray: false  auto: false  col: nvarchar        len: 10      default: []
	PostalCode sql.NullString `gorm:"column:PostalCode;type:nvarchar;size:10;" json:"postal_code"`
	//[ 9] Phone                                          nvarchar(24)         null: true   primary: false  isArray: false  auto: false  col: nvarchar        len: 24      default: []
	Phone sql.NullString `gorm:"column:Phone;type:nvarchar;size:24;" json:"phone"`
	//[10] Fax                                            nvarchar(24)         null: true   primary: false  isArray: false  auto: false  col: nvarchar        len: 24      default: []
	Fax sql.NullString `gorm:"column:Fax;type:nvarchar;size:24;" json:"fax"`
	//[11] Email                                          nvarchar(60)         null: false  primary: false  isArray: false  auto: false  col: nvarchar        len: 60      default: []
	Email string `gorm:"column:Email;type:nvarchar;size:60;" json:"email"`
	//[12] SupportRepId                                   integer              null: true   primary: false  isArray: false  auto: false  col: integer         len: -1      default: []
	SupportRepID sql.NullInt64 `gorm:"column:SupportRepId;type:integer;" json:"support_rep_id"`
}

var customersTableInfo = &TableInfo{
	Name: "customers",
	Columns: []*ColumnInfo{

		{
			Index:              0,
			Name:               "CustomerId",
			Comment:            ``,
			Notes:              ``,
			Nullable:           false,
			DatabaseTypeName:   "integer",
			DatabaseTypePretty: "integer",
			IsPrimaryKey:       true,
			IsAutoIncrement:    true,
			IsArray:            false,
			ColumnType:         "integer",
			ColumnLength:       -1,
			GoFieldName:        "CustomerID",
			GoFieldType:        "int32",
			JSONFieldName:      "customer_id",
			ProtobufFieldName:  "customer_id",
			ProtobufType:       "int32",
			ProtobufPos:        1,
		},

		{
			Index:              1,
			Name:               "FirstName",
			Comment:            ``,
			Notes:              ``,
			Nullable:           false,
			DatabaseTypeName:   "nvarchar",
			DatabaseTypePretty: "nvarchar(40)",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "nvarchar",
			ColumnLength:       40,
			GoFieldName:        "FirstName",
			GoFieldType:        "string",
			JSONFieldName:      "first_name",
			ProtobufFieldName:  "first_name",
			ProtobufType:       "string",
			ProtobufPos:        2,
		},

		{
			Index:              2,
			Name:               "LastName",
			Comment:            ``,
			Notes:              ``,
			Nullable:           false,
			DatabaseTypeName:   "nvarchar",
			DatabaseTypePretty: "nvarchar(20)",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "nvarchar",
			ColumnLength:       20,
			GoFieldName:        "LastName",
			GoFieldType:        "string",
			JSONFieldName:      "last_name",
			ProtobufFieldName:  "last_name",
			ProtobufType:       "string",
			ProtobufPos:        3,
		},

		{
			Index:              3,
			Name:               "Company",
			Comment:            ``,
			Notes:              ``,
			Nullable:           true,
			DatabaseTypeName:   "nvarchar",
			DatabaseTypePretty: "nvarchar(80)",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "nvarchar",
			ColumnLength:       80,
			GoFieldName:        "Company",
			GoFieldType:        "sql.NullString",
			JSONFieldName:      "company",
			ProtobufFieldName:  "company",
			ProtobufType:       "string",
			ProtobufPos:        4,
		},

		{
			Index:              4,
			Name:               "Address",
			Comment:            ``,
			Notes:              ``,
			Nullable:           true,
			DatabaseTypeName:   "nvarchar",
			DatabaseTypePretty: "nvarchar(70)",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "nvarchar",
			ColumnLength:       70,
			GoFieldName:        "Address",
			GoFieldType:        "sql.NullString",
			JSONFieldName:      "address",
			ProtobufFieldName:  "address",
			ProtobufType:       "string",
			ProtobufPos:        5,
		},

		{
			Index:              5,
			Name:               "City",
			Comment:            ``,
			Notes:              ``,
			Nullable:           true,
			DatabaseTypeName:   "nvarchar",
			DatabaseTypePretty: "nvarchar(40)",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "nvarchar",
			ColumnLength:       40,
			GoFieldName:        "City",
			GoFieldType:        "sql.NullString",
			JSONFieldName:      "city",
			ProtobufFieldName:  "city",
			ProtobufType:       "string",
			ProtobufPos:        6,
		},

		{
			Index:              6,
			Name:               "State",
			Comment:            ``,
			Notes:              ``,
			Nullable:           true,
			DatabaseTypeName:   "nvarchar",
			DatabaseTypePretty: "nvarchar(40)",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "nvarchar",
			ColumnLength:       40,
			GoFieldName:        "State",
			GoFieldType:        "sql.NullString",
			JSONFieldName:      "state",
			ProtobufFieldName:  "state",
			ProtobufType:       "string",
			ProtobufPos:        7,
		},

		{
			Index:              7,
			Name:               "Country",
			Comment:            ``,
			Notes:              ``,
			Nullable:           true,
			DatabaseTypeName:   "nvarchar",
			DatabaseTypePretty: "nvarchar(40)",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "nvarchar",
			ColumnLength:       40,
			GoFieldName:        "Country",
			GoFieldType:        "sql.NullString",
			JSONFieldName:      "country",
			ProtobufFieldName:  "country",
			ProtobufType:       "string",
			ProtobufPos:        8,
		},

		{
			Index:              8,
			Name:               "PostalCode",
			Comment:            ``,
			Notes:              ``,
			Nullable:           true,
			DatabaseTypeName:   "nvarchar",
			DatabaseTypePretty: "nvarchar(10)",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "nvarchar",
			ColumnLength:       10,
			GoFieldName:        "PostalCode",
			GoFieldType:        "sql.NullString",
			JSONFieldName:      "postal_code",
			ProtobufFieldName:  "postal_code",
			ProtobufType:       "string",
			ProtobufPos:        9,
		},

		{
			Index:              9,
			Name:               "Phone",
			Comment:            ``,
			Notes:              ``,
			Nullable:           true,
			DatabaseTypeName:   "nvarchar",
			DatabaseTypePretty: "nvarchar(24)",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "nvarchar",
			ColumnLength:       24,
			GoFieldName:        "Phone",
			GoFieldType:        "sql.NullString",
			JSONFieldName:      "phone",
			ProtobufFieldName:  "phone",
			ProtobufType:       "string",
			ProtobufPos:        10,
		},

		{
			Index:              10,
			Name:               "Fax",
			Comment:            ``,
			Notes:              ``,
			Nullable:           true,
			DatabaseTypeName:   "nvarchar",
			DatabaseTypePretty: "nvarchar(24)",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "nvarchar",
			ColumnLength:       24,
			GoFieldName:        "Fax",
			GoFieldType:        "sql.NullString",
			JSONFieldName:      "fax",
			ProtobufFieldName:  "fax",
			ProtobufType:       "string",
			ProtobufPos:        11,
		},

		{
			Index:              11,
			Name:               "Email",
			Comment:            ``,
			Notes:              ``,
			Nullable:           false,
			DatabaseTypeName:   "nvarchar",
			DatabaseTypePretty: "nvarchar(60)",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "nvarchar",
			ColumnLength:       60,
			GoFieldName:        "Email",
			GoFieldType:        "string",
			JSONFieldName:      "email",
			ProtobufFieldName:  "email",
			ProtobufType:       "string",
			ProtobufPos:        12,
		},

		{
			Index:              12,
			Name:               "SupportRepId",
			Comment:            ``,
			Notes:              ``,
			Nullable:           true,
			DatabaseTypeName:   "integer",
			DatabaseTypePretty: "integer",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "integer",
			ColumnLength:       -1,
			GoFieldName:        "SupportRepID",
			GoFieldType:        "sql.NullInt64",
			JSONFieldName:      "support_rep_id",
			ProtobufFieldName:  "support_rep_id",
			ProtobufType:       "int32",
			ProtobufPos:        13,
		},
	},
}

// TableName sets the insert table name for this struct type
func (c *Customers) TableName() string {
	return "customers"
}

// BeforeSave invoked before saving, return an error if field is not populated.
func (c *Customers) BeforeSave() error {
	return nil
}

// Prepare invoked before saving, can be used to populate fields etc.
func (c *Customers) Prepare() {
}

// Validate invoked before performing action, return an error if field is not populated.
func (c *Customers) Validate(action Action) error {
	return nil
}

// TableInfo return table meta data
func (c *Customers) TableInfo() *TableInfo {
	return customersTableInfo
}
